(function (G) {
    G.vue({
        data: {
            patroltype: null,
            spot: [], //显示所有有任务的日期
            taskList: [], // 所选日期的所有案件
            locationIcon: G.Storage.get('APIURL') + '/file/1593488692939460608',
        },
        methods: {
            toTask() {
                wx.navigateTo({
                    url: '/pages/gypatrol/Task/index',
                })
            },
            dateChange(e) {
                console.log('----change', e.detail.dateString);
                this.getTask(e.detail.dateString)
            },
            getTask(dateStr) {
                G.get('/api/model/g_patrol_record', {
                    'patrolDate': dateStr,
                    userId: G.Storage.get('userInfo').id,
                    patroltype: this.data.patroltype
                }).then(res => {
                    console.log(res);
                    this.setData({
                        taskList: res
                    })
                })
                // G.get('/api/model/g_patrol_task', {
                //     'patrolDate': dateStr,
                //     userId: G.Storage.get('userInfo').id,
                //     patroltype: this.data.patroltype
                // }).then(res => {
                //     console.log(res);
                //     this.setData({
                //         taskList: res
                //     })
                // })
            },
            // 获取自己所有的任务
            getAllPatrolDate(patroltype) {
                G.get('/api/model/g_patrol_record', {
                    userId: G.Storage.get('userInfo').id,
                    patroltype: patroltype
                }).then(res => {
                    console.log('--spot', res);
                    let allDate = []
                    // let allRecord = []
                    res.forEach(e => {
                        if (e.local) {
                            allDate.push(e.patrolDate)
                            // allRecord.push(e)
                        }
                    })
                    this.setData({
                        spot: allDate
                    })
                    this.getNowTask()
                })
                // G.get('/api/model/g_patrol_task', {
                //     userId: G.Storage.get('userInfo').id,
                //     patroltype: patroltype
                // }).then(res => {
                //     console.log('--spot', res);
                //     let allDate = []
                //     res.forEach(e => {
                //         allDate.push(e.patrolDate)
                //     })
                //     this.setData({
                //         spot: allDate
                //     })
                //     this.getNowTask()
                // })
            },
            toTaskPage() {
                wx.reLaunch({
                    url: '/pages/gypatrol/Task/index',
                })
            },
            getNowTask() {
                let day = this.formatDate(new Date())
                console.log('---day', day);
                this.getTask(day)
            },
            // 格式化时间--年月日
            formatDate(times) {
                var date = new Date(times);
                var year = date.getFullYear().toString(); //年份
                var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString() //月份
                // (date.getMonth() + 1).toString(); 
                var day1 = date.getDate(); //日
                if (day1.toString().length == 1) {
                    var day = '0' + day1.toString()
                } else {
                    var day = day1.toString()
                }
                var hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
                var minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
                var second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                return year + '-' + month + '-' + day
                //   year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
            },


        },
        /**
         * init
         */
        mounted(opt) {
            this.setData({
                patroltype: opt.patroltype
            })
            this.getAllPatrolDate(opt.patroltype)
        }
    })
})(wx.$)